package com.ip.student.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ip.common.constant.Result;
import com.ip.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ip.student.models.service.IStudentInfoService;
import com.ip.student.models.bo.StudentInfoBO;
import com.ip.student.models.dto.StudentInfoDTO;

/**
 * 学生基本信息控制器
 *
 * @author 张景奇
 * @Date 2025-11-03 09:19:06
 */

@RestController
@RequestMapping("/api/studentInfo")
@Slf4j
@Api(value = "StudentInfoApiController",tags = "学生基本信息Api接口")
public class StudentInfoApiController {

    @DubboReference
    private IStudentInfoService studentInfoService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<StudentInfoDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        StudentInfoDTO dto = studentInfoService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "学生基本信息列表",notes = "学生基本信息列表")
    @PostMapping("/queryPageList")
    public Result<Page<StudentInfoDTO>> queryPageList(StudentInfoBO bo){
        Wrapper<StudentInfoDTO> wrapper = new EntityWrapper<>();

        Page<StudentInfoDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = studentInfoService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
